home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / TouchMe 1.2□ / touchMe 1.2 Folder / touchMe source codes / CW11 PP source / source / CTouchMePref.cp < prev    next >
Encoding:
Text File  |  1997-04-25  |  6.3 KB  |  322 lines  |  [TEXT/CWIE]

  1. // ==================================================
  2. //    CTouchMePref.cp
  3. //    Copyright (C) 1996-1997 Mizutori Tetsuya
  4. //    July 4, 1996;  February 3, 1997; April 23, 1997.
  5. // ==================================================
  6. //    All documents are pretty-printed in 10-point Geneva font.
  7.  
  8. #pragma once
  9.  
  10. #include <OSUtils.h>
  11.  
  12. #include <UMemoryMgr.h>
  13. #include <LString.h>
  14.  
  15. #include "touchMeConstants.h"
  16. #include "CTouchMeMainWindow.h"
  17. #include "CPrefsFile.h"
  18. #include "CTouchMePref.h"
  19. #include "UDateTime.h"
  20.  
  21.  
  22. const    ResType    PREF_ResType        = 'PREF';
  23. const    ResIDT    PREF_ResID        = 1000;
  24.  
  25.  
  26. // --------------------------------------------------
  27. //        • CTouchMePref()
  28. // --------------------------------------------------
  29.  
  30. CTouchMePref::CTouchMePref()
  31. {
  32.     SetupConstants();
  33. }
  34.  
  35.  
  36. // --------------------------------------------------
  37. //        • CTouchMePref()
  38. // --------------------------------------------------
  39.  
  40. CTouchMePref::CTouchMePref(
  41.     ConstStr255Param    inFileName )
  42.         : CPrefsFile( inFileName, kThisApplicationCreatorType )
  43. {
  44.     SetupConstants();
  45. }
  46.  
  47.  
  48. // --------------------------------------------------
  49. //        • ~CTouchMePref
  50. // --------------------------------------------------
  51.  
  52. CTouchMePref::~CTouchMePref()
  53. {
  54. }
  55.  
  56. // --------------------------------------------------
  57. //        • SetupConstants
  58. // --------------------------------------------------
  59.  
  60. void
  61. CTouchMePref::SetupConstants( void )
  62. {
  63.     // Do nothing here.
  64. }
  65.  
  66.  
  67. // ==================================================
  68. //    Member functions
  69. // ==================================================
  70.  
  71. // --------------------------------------------------
  72. //        • LoadPrefsData
  73. // --------------------------------------------------
  74.  
  75. OSErr
  76. CTouchMePref::LoadPrefsData( void )
  77. {
  78.     OSErr    err;
  79.  
  80.     long                theSizeInBytes = 0;
  81.     StClearHandleBlock    thePref( 0 );
  82.  
  83.     SPrefsHandle        thePrefsH =  (SPrefsHandle) (thePref.mHandle);
  84.     err = LoadPrefs( theSizeInBytes, (Handle) thePrefsH, PREF_ResType, PREF_ResID );
  85.  
  86.     if ( err == noErr ) {
  87.         mPrefs = **thePrefsH;
  88.         TransformToSettings();
  89.     }
  90.  
  91.     return noErr;
  92. }
  93.  
  94.  
  95. // --------------------------------------------------
  96. //        • SavePrefsData
  97. // --------------------------------------------------
  98.  
  99. OSErr
  100. CTouchMePref::SavePrefsData( void)
  101. {
  102.     OSErr    err;
  103.  
  104.     TransformFromSettings();
  105.  
  106.     long                theSizeInBytes = 0;
  107.     StClearHandleBlock    thePref( 0 );
  108.  
  109.     SPrefsHandle        thePrefsH =  (SPrefsHandle) (thePref.mHandle);
  110.     theSizeInBytes = sizeof(SPrefsRec);
  111.  
  112.     ::PtrToXHand( (void *) &mPrefs, (Handle) thePrefsH, theSizeInBytes );
  113.     err = SavePrefs( theSizeInBytes, (Handle) thePrefsH, PREF_ResType, PREF_ResID );
  114.  
  115.     return noErr;
  116. }
  117.  
  118.  
  119. // --------------------------------------------------
  120. //        • SetPrefsToWindow
  121. // --------------------------------------------------
  122. // Set the window's settings by prefs data.
  123.  
  124. void
  125. CTouchMePref::SetPrefsToWindow(
  126.     LWindow *        inWindow )
  127. {
  128.  
  129.     switch ( inWindow->GetUserCon() ) {
  130.  
  131.         case CTouchMeMainWindow::class_ID:
  132.         {
  133.             TransformFromSettings();
  134.             CTouchMeMainWindow *    theWindow = (CTouchMeMainWindow *) inWindow;
  135.             theWindow->SetupDialog( mPrefs );
  136.         }
  137.         break;
  138.  
  139.     }
  140.  
  141. }
  142.  
  143.  
  144. // --------------------------------------------------
  145. //        • GetPrefsFromWindow
  146. // --------------------------------------------------
  147. // Get the window's settings to prefs data.
  148.  
  149. void
  150. CTouchMePref::GetPrefsFromWindow(
  151.     LWindow *        inWindow )
  152. {
  153.  
  154.     switch ( inWindow->GetUserCon() ) {
  155.  
  156.         case CTouchMeMainWindow::class_ID:
  157.         {
  158.             CTouchMeMainWindow *    theWindow = (CTouchMeMainWindow *) inWindow;
  159.             theWindow->InspectDialog( mPrefs );
  160.             TransformToSettings();
  161.         }
  162.         break;
  163.  
  164.     }
  165.  
  166. }
  167.  
  168.  
  169. // --------------------------------------------------
  170. //        • TransformToSettings
  171. // --------------------------------------------------
  172.  
  173. void
  174. CTouchMePref::TransformToSettings( void )
  175. {
  176.     // Do nothing here.
  177. }
  178.  
  179.  
  180. // --------------------------------------------------
  181. //        • TransformFromSettings
  182. // --------------------------------------------------
  183.  
  184. void
  185. CTouchMePref::TransformFromSettings( void )
  186. {
  187.     // Do nothing here.
  188. }
  189.  
  190.  
  191. // ==================================================
  192. //    Member functions (preferences data)
  193. // ==================================================
  194. // Retrieve preferences data.
  195.  
  196. // --------------------------------------------------
  197. //        • {Set/Get}WindowRect
  198. // --------------------------------------------------
  199.  
  200. void
  201. CTouchMePref::SetWindowRect(
  202.     Rect &    inWindowRect )
  203. {
  204.     mPrefs.wframe = inWindowRect;
  205. }
  206.  
  207.  
  208. void
  209. CTouchMePref::GetWindowRect(
  210.     Rect &    outWindowRect )
  211. {
  212.     outWindowRect = mPrefs.wframe;
  213. }
  214.  
  215.  
  216. // --------------------------------------------------
  217. //        • {Set/Get}Sync
  218. // --------------------------------------------------
  219.  
  220. void
  221. CTouchMePref::SetSync(
  222.     const Boolean    inStatus )
  223. {
  224.     mPrefs.sync = inStatus;
  225. }
  226.  
  227.  
  228. Boolean
  229. CTouchMePref::GetSync( void )
  230. {
  231.     return mPrefs.sync;
  232. }
  233.  
  234.  
  235. // --------------------------------------------------
  236. //        • {Set/Get}Enabled
  237. // --------------------------------------------------
  238.  
  239. void
  240. CTouchMePref::SetEnabled(
  241.     const ETouchType    inType,
  242.     const Boolean        inStatus )
  243. {
  244.     mPrefs.enabled[ inType - touchType_CreationDate ] = inStatus;
  245. }
  246.  
  247.  
  248. Boolean
  249. CTouchMePref::GetEnabled(
  250.     const ETouchType    inType )
  251. {
  252.     return mPrefs.enabled[ inType - touchType_CreationDate ];
  253. }
  254.  
  255.  
  256. // --------------------------------------------------
  257. //        • {Set/Get}Flag
  258. // --------------------------------------------------
  259.  
  260. void
  261. CTouchMePref::SetFlag(
  262.     const ETouchType    inType,
  263.     const ETouchFlag        inFlag,
  264.     const Boolean        inStatus )
  265. {
  266.     if ( inStatus ) mPrefs.flag[ inType - touchType_CreationDate ] = inFlag;
  267. }
  268.  
  269.  
  270. Boolean
  271. CTouchMePref::GetFlag(
  272.     const ETouchType    inType,
  273.     const ETouchFlag        inFlag )
  274. {
  275.     return ( mPrefs.flag[ inType - touchType_CreationDate ] == inFlag );
  276. }
  277.  
  278.  
  279. // --------------------------------------------------
  280. //        • {Set/Get}FlagNumb
  281. // --------------------------------------------------
  282.  
  283. void
  284. CTouchMePref::SetFlagNumb(
  285.     const ETouchType    inType,
  286.     const ETouchFlag        inFlag )
  287. {
  288.     mPrefs.flag[ inType - touchType_CreationDate ] = inFlag;
  289. }
  290.  
  291.  
  292. ETouchFlag
  293. CTouchMePref::GetFlagNumb(
  294.     const ETouchType    inType )
  295. {
  296.     return  (ETouchFlag) mPrefs.flag[ inType - touchType_CreationDate ];
  297. }
  298.  
  299.  
  300. // --------------------------------------------------
  301. //        • {Set/Get}DateTime
  302. // --------------------------------------------------
  303.  
  304. void
  305. CTouchMePref::SetDateTime(
  306.     const ETouchType    inType,
  307.     const unsigned long    inValue)
  308. {
  309.     mPrefs.datetime[ inType - touchType_CreationDate ] = inValue;
  310. }
  311.  
  312.  
  313. unsigned long
  314. CTouchMePref::GetDateTime(
  315.     const ETouchType    inType )
  316. {
  317.     return mPrefs.datetime[ inType - touchType_CreationDate ];
  318. }
  319.  
  320.  
  321. // end of program
  322.